// Time.cpp : Defines the entry point for the console application.
//

#ifndef __TINY_LOG__
#define __TINY_LOG__

#include <assert.h>
#include <fstream>
#include <stdarg.h>
#include <string>

std::string getTimeStamp();

class MyLog
{
public:
    MyLog(std::string filename, bool timestamp = true)
    {
        if (timestamp)
        {
            filename += '_' + getTimeStamp();
        }
        filename += ".txt";
        f.open(filename, std::ios::app);
        assert(f.is_open());
    }

    ~MyLog()
    {
        assert(f.is_open());
        f.close();
    }

    void Log(const char* fmt, ...)
    {
        assert(f.is_open());
        va_list argp;
        va_start(argp, fmt);
        vsprintf_s(buf, sizeof(buf), fmt, argp);
        va_end(argp);
        f << buf << std::endl;
    }
private:
    char buf[1024];
    std::ofstream f;
};

#endif // !__TINY_LOG__
